package performanceTest;

import java.util.Iterator;
import java.util.LinkedList;

import org.junit.Before;
import org.junit.Test;

public class PerformanceTestLinkedList {
	
	private int count = 100_000_000;
	private LinkedList<String> list = new LinkedList<>();
	
	@Before
	public void init(){
		for(int i = 0; i < count; i++){
			list.add(String.valueOf(i));
		}
	}

	@Test
	public void iterator(){
		
		Iterator<String> iterator = list.iterator();
		while(iterator.hasNext()){
			iterator.next();
		}
	}
	
	@Test
	public void forEach(){
		for(String item : list){
			
		}
	}
	
	
//	@Test
//	public void forIndex(){  //非常低效
//		for(int i = 0; i < count; i++){
//			list.get(i);
//		}
//	}
	
	@Test 
	public void lambda(){
		list.stream().forEach((a) -> {});
	} 
}
